package dialogs
{
	import UIFree.controls.uif_label;
	import UIFree.uif_component;
	import editor.*;
	
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class pi_user extends pi_source {
		private var _userData:*;
		private var _mask: uif_component;
		private var _label: uif_label;
		public function pi_user(parent:uif_component, a_userData:*, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
			_userData = a_userData;
			var inner: Rectangle = getInner();
			_mask = new uif_component(this, inner.x, inner.y, inner.width, inner.width, 'white');
			_label = new uif_label(this, inner.x, _mask.y + _mask.height, 
										inner.width, 40, 'userName');
			this.loadSource(_userData.pic);
			
			_label.text = pi_app.userName(_userData);
		}
		
		public function get userData(): * {
			return _userData;
		}

		override protected function doLoad(e: Event): void {
			if ((_source.width < _mask.width) || 
				(_source.height < _mask.height)) {
				var kof: Number = _source.height / _source.width;
				if (kof > 1) {
					_source.width  = _mask.width;
					_source.height = _mask.width * kof;
				} else {
					_source.height = _mask.width;
					_source.width  = _mask.width / kof;
				}
			}
			_source.x = _mask.x + (_mask.width  - _source.width) / 2; 
			_source.y = _mask.y + (_mask.height - _source.height) / 2; 
			_source.mask = _mask;
		}
	}
}